<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>对象方法</title>
  <script type="text/javascript">
    // 两种传统的对象方法声明方式
    let person = {
      name: "tom",
      age: 18,
      sayHi: function () {
        console.log("Hi,", this.name);
      }
    }
    person.sayHi();
    person.sayHello = function () {
      console.log("Hello,", this.name);
    }
    person.sayHello();
    // ES6简化对象声明方式
    let dog = {
      name: "bob",
      age: 2,
      shout() {
        console.log(this.name, "barks!");// 引用对象属性必须加this
      }
    }
    dog.shout();
  </script>
</head>
<body>
</body>
</html>
